﻿<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
  xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
  version="1.0" exclude-result-prefixes="xsl msxsl ddwrt x d asp __designer SharePoint ddwrt2"
  xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
  xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
  xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:SharePoint="Microsoft.SharePoint.WebControls"
  xmlns:ddwrt2="urn:frontpage:internal">
  <xsl:import href="/_layouts/xsl/main.xsl"/>
  <xsl:output method="html" indent="no"/>
  <xsl:param name="Picking" select="'no'"/>
  <xsl:param name="ThumbStyle" select="'medium'"/>
  <xsl:param name="Viewing" select="''"/>
  <xsl:param name ="ParentId" select="''"/>
  <xsl:param name ="URL_Library" select="''"/>
  <xsl:param name ="URL_ItemDisplay" select="''"/>
  <xsl:param name ="ThumbnailSize" select="''"/>
  <xsl:param name="WebImageWidth" select="''"/>
  <xsl:param name="WebImageHeight" select="''"/>
  <xsl:param name="PagePathFinal" select="concat($PagePath,'?')"/>
  <xsl:param name="CanEdit" select="''"/>
  <xsl:param name="FolderUrlAdditionalQueryString" select="''"/>
  <xsl:variable name="LibraryUrl">
    <xsl:choose>
      <xsl:when test="string-length($URL_Library)=0">
        <xsl:value-of select="concat($ListUrlDir,'/')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$URL_Library"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="squote">'</xsl:variable>
  <xsl:variable name="dquote">"</xsl:variable>
  <xsl:variable name="StylePath">
    <xsl:value-of select="concat($HttpVDir,'/','_layouts/',$LCID,'/styles')" />
  </xsl:variable>
  <xsl:variable name="NonLocScriptPath">
    <xsl:value-of select="concat($HttpVDir,'/','_layouts')" />
  </xsl:variable>
  <xsl:variable name="LocScriptPath">
    <xsl:value-of select="concat($NonLocScriptPath,'/',$LCID)" />
  </xsl:variable>
  <xsl:variable name="NumPropsToShow">1</xsl:variable>
  <xsl:variable name="StyleToApply">ms-assetpicker-tiled-mediumthumbs</xsl:variable>
  <xsl:variable name="CBXStyle" select="'display: none;'"></xsl:variable>
  <xsl:variable name="StyleForHiding" select="'ms-assetpicker-hide'"/>
  <xsl:template name="FieldRef_Menu_PrintFieldAP" match="FieldRef[@EcbMenu='TRUE']" mode="PrintFieldWithECB" ddwrt:ghost="always">
    <xsl:param name="thisNode" select="."/>
    <xsl:choose>
      <xsl:when test="$Picking = 'yes'">
        <xsl:call-template name="FieldRef_NoMenu_PrintFieldWithECB">
          <xsl:with-param name="thisNode" select="$thisNode"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="FieldRef_Menu_PrintFieldWithECB">
          <xsl:with-param name="thisNode" select="$thisNode"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="FieldRef" name="LinkFilenameNoMenuAP" mode="Computed_LinkFilename_body" ddwrt:tag="a" ddwrt:ghost="always">
    <xsl:param name="thisNode" select="."/>
    <xsl:param name="ShowAccessibleIcon" select="0"/>
    <xsl:param name="ShowNonContainerLinkOnly" select="0"/>
    <xsl:choose>
      <xsl:when test="$Picking = 'yes' and $thisNode/@FSObjType != '1'">
        <a href="javascript:;">
          <xsl:value-of select="$thisNode/@FileLeafRef.Name" />
        </a>
      </xsl:when>
      <xsl:when test="$thisNode/@FSObjType = '1' and ($Picking = 'yes' or $ShowNonContainerLinkOnly = '1')">
        <xsl:call-template name="LinkFilenameNoMenu">
          <xsl:with-param name="thisNode" select="$thisNode"/>
          <xsl:with-param name="ShowAccessibleIcon" select="$ShowAccessibleIcon"/>
          <xsl:with-param name="IncludeOnClick">
            <xsl:choose>
              <xsl:when test="$Picking = 'yes'">0</xsl:when>
              <xsl:otherwise>1</xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$ShowNonContainerLinkOnly = '1'">
            <!--do this directly rather than call below to cut out new file status image-->
            <a onfocus="OnLink(this)" href="{$thisNode/@FileRef}" onclick="return DispEx(this,event,'TRUE','FALSE','{$thisNode/@File_x0020_Type.url}','{$thisNode/@File_x0020_Type.progid}','{$XmlDefinition/List/@DefaultItemOpen}','{$thisNode/@HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon}','{$thisNode/@HTML_x0020_File_x0020_Type}','{$thisNode/@serverurl.progid}','{$thisNode/@CheckoutUser.id}','{$Userid}','{$XmlDefinition/List/@ForceCheckout}','{$thisNode/@IsCheckedoutToLocal}','{$thisNode/@PermMask}')">
              <xsl:value-of select="$thisNode/@FileLeafRef.Name" />
            </a>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="LinkFilenameNoMenu">
              <xsl:with-param name="thisNode" select="$thisNode"/>
              <xsl:with-param name="ShowAccessibleIcon" select="$ShowAccessibleIcon"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="FieldRef" name="LinkTitleNoMenuAP" mode="Computed_LinkTitle_body" ddwrt:tag="a" ddwrt:ghost="always">
    <xsl:param name="thisNode" select="."/>
    <xsl:param name="ShowAccessibleIcon" select="0"/>
    <xsl:choose>
      <xsl:when test="$Picking = 'yes' and $thisNode/@FSObjType != '1'">
        <a href="javascript:;">
          <xsl:call-template name="LinkTitleValue">
            <xsl:with-param name="thisNode" select="$thisNode"/>
            <xsl:with-param name="ShowAccessibleIcon" select="$ShowAccessibleIcon"/>
          </xsl:call-template>
        </a>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="LinkTitleNoMenu">
          <xsl:with-param name="thisNode" select="$thisNode"/>
          <xsl:with-param name="folderUrlAdditionalQueryString" select="$FolderUrlAdditionalQueryString"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="View_Default_RootTemplateAP" mode="RootTemplate" match="View[@BaseViewID='4']" ddwrt:dvt_mode="root" ddwrt:ghost="always">
    <!--Initialize JavaScript globals-->
    <xsl:call-template name="clientPageArray"/>
    <div id="pickerimages" class="ms-assetpicker-untiled">
      <xsl:call-template name="View_Default_RootTemplate">
        <xsl:with-param name="ShowSelectAllCheckbox" select="'False'"/>
      </xsl:call-template>
    </div>
  </xsl:template>
  <xsl:template match="View[@BaseViewID='40']" mode="full" ddwrt:ghost="always">
    <!--Initialize JavaScript globals-->
    <xsl:call-template name="clientPageArray"/>
    <tr class="ms-viewheadertr"></tr>
    <tr>
      <td>
        <ul id="pickerimages" class="ms-assetpicker-tiled">
          <xsl:apply-templates select="." mode="RenderView" />
        </ul>
      </td>
    </tr>
    <xsl:apply-templates mode="footer" select="." />
  </xsl:template>
  <!--Client-side Bootstrapping-->
  <xsl:template name="clientPageArray" ddwrt:ghost="always">
    <xsl:choose>
      <xsl:when test ="$Picking='yes'">
        <!--Page globals for Picking-->
        <input type="hidden" name="assetpicking">
          <xsl:attribute name="value">
            <xsl:value-of select="$Picking"/>
          </xsl:attribute>
        </input>
        <input type="hidden" name="webpartclientid" xsl:exclude-result-prefixes="SharePoint">
          <xsl:attribute name="value">
            <xsl:value-of select="$WebPartClientID"/>
          </xsl:attribute>
        </input>
        <input type="hidden" name="listid">
          <xsl:attribute name="value">
            <xsl:value-of select="$List"/>
          </xsl:attribute>
        </input>
        <input type="hidden" name="thumbnailsize">
          <xsl:attribute name="value">
            <xsl:value-of select="$ThumbnailSize"/>
          </xsl:attribute>
        </input>
        <input type="hidden" name="webimagewidth">
          <xsl:attribute name="value">
            <xsl:value-of select="$WebImageWidth"/>
          </xsl:attribute>
        </input>
        <input type="hidden" name="webimageheight">
          <xsl:attribute name="value">
            <xsl:value-of select="$WebImageHeight"/>
          </xsl:attribute>
        </input>
        <input type="hidden" name="canedit">
          <xsl:attribute name="value">
            <xsl:value-of select="$CanEdit"/>
          </xsl:attribute>
        </input>
        <script>
          if("function" == typeof(AssetPickerPageCache)) g_AssetPickerPageCache = new AssetPickerPageCache();
          if("function" == typeof(AssetPickerXslContext)) g_AssetPickerXslContext = new AssetPickerXslContext();
        </script>
      </xsl:when>
      <xsl:otherwise>
        <script type="text/javascript">
          var g_Rev = <xsl:value-of select="concat($squote,ddwrt:GetCurrentBuildVersion(),$squote)"/>;
          var g_AllowSilverlightPrompt = <xsl:value-of select="ddwrt:AllowSilverlightPrompt()"/>;
          <![CDATA[
          var g_APD_ScriptsLoaded = 0;
          var g_APD_CsssLoaded = 0;
          function APD_CallbackWssView(who)
          {
            if("function" == typeof(window.status)) window.status('Boot Strap Callback from ' + who);
          }
          function SmtAddWindowLoadEvent(handlerFunc)
          {
            if (window.attachEvent)
            {
                window.attachEvent("onload", handlerFunc);
            }
            else if (window.addEventListener)
            {
                window.addEventListener("load", handlerFunc, false);
            }
          }
          function APD_EnsureLoadHandlers()
          {
            EnsureScript("CMSSiteManager.js", typeof(AssetPickerPageCache), APD_LoadHandlers);
          }
          function APD_LoadHandlers()
          {
            g_AssetPickerPageCache = new AssetPickerPageCache();
            g_AssetPickerXslContext = new AssetPickerXslContext();
            EnsureScript("AssetPickers.js", typeof(AP_IsEmpty), APD_InitializeAssetPickerElements);
          }
          function APD_SimpleCacheControl()
          {
            return g_Rev;
          }
          function APD_AddStyleSheet(hrefValue)
          {
            if (!document.getElementsByTagName
            || !(document.createElement || document.createElementNS)) return;
            var head = document.getElementsByTagName("head")[0];
            var link = document.createElement("link");
            link.setAttribute('type', 'text/css');
            link.setAttribute('rel', 'stylesheet');
            link.setAttribute('media', 'screen');
            var rev = APD_SimpleCacheControl();
            var url = hrefValue + "?rev="+rev;
            link.setAttribute('href', url);
            head.appendChild(link);
            return false;
          }
          function APD_AddScript(hrefValue)
          {
            if (!document.getElementsByTagName
            || !(document.createElement || document.createElementNS)) return;
            var loc = document.getElementsByTagName("head")[0];
            var rev = APD_SimpleCacheControl();
            var link = document.createElement("script");
            link.setAttribute('type', 'text/javascript');
            var url = hrefValue + "?rev="+rev;
            link.setAttribute('src', url);
            loc.appendChild(link);
            link.onload = function () 
            {
              g_APD_ScriptsLoaded++;
              if("function" == typeof(window.status)) window.status("Script #" + g_APD_ScriptsLoaded + " loaded");
            }
            return false;
          }
        ]]>
          if(document.g_APD_isFFScriptLoaded == undefined)
          {
          APD_AddStyleSheet(<xsl:value-of select="concat($squote,$StylePath,'/portal.css',$squote)"/>);
          APD_AddScript(<xsl:value-of select="concat($squote,$LocScriptPath,'/CMSSiteManager.js',$squote)"/>);
          APD_AddScript(<xsl:value-of select="concat($squote,$LocScriptPath,'/AssetPickers.js',$squote)"/>);
          APD_AddScript(<xsl:value-of select="concat($squote,$NonLocScriptPath,'/MediaPlayer.js',$squote)"/>);
          SmtAddWindowLoadEvent(APD_EnsureLoadHandlers);
          document.g_APD_isFFScriptLoaded = true;
          }
        </script>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="ItemData" mode="ClientData" match="Row" ddwrt:ghost="always">
    <xsl:param name ="thisNode" select="."/>
    <xsl:variable name="imageId" select="concat('tiledimage_',$thisNode/@ID)"/>
    <input type="checkbox">
      <xsl:attribute name="style">
        <xsl:choose>
          <xsl:when test="$Picking='yes'">
            <xsl:value-of select="$CBXStyle"/>
          </xsl:when>
          <xsl:otherwise>display:inline;</xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:attribute name="id">
        <xsl:value-of select="$thisNode/@ID"/>
      </xsl:attribute>
      <xsl:attribute name="name">
        <xsl:value-of select="'ImageItem'"/>
      </xsl:attribute>
      <xsl:attribute name="iid">
        <xsl:value-of select="$ViewCounter"/>,<xsl:value-of select="$thisNode/@ID"/>,<xsl:value-of select="$thisNode/@FSObjType"/>
      </xsl:attribute>
      <xsl:attribute name="value">
        <xsl:call-template name="clientData">
          <xsl:with-param name="id" select="$imageId"/>
          <xsl:with-param name="canEdit">
            <xsl:variable name="hasRight">
              <xsl:call-template name="IfHasRight">
                <xsl:with-param name="thisNode" select ="$thisNode"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:value-of select="number($hasRight)"/>
          </xsl:with-param>
          <xsl:with-param name="previewExists" select="$thisNode/@PreviewExists.value"/>
          <xsl:with-param name="thumbnailExists" select="$thisNode/@ThumbnailExists.value"/>
          <xsl:with-param name="alternateThumbnailUrl" select="$thisNode/@AlternateThumbnailUrl"/>
          <xsl:with-param name="parentId" select="$ParentId"/>
          <xsl:with-param name="propsUrl" select="concat($FORM_DISPLAY, '&amp;ID=',$thisNode/@ID)"/>
          <xsl:with-param name ="dwnlUrl" select ="concat($HttpVDir,'/_layouts/Download.aspx?SourceUrl=',$thisNode/@FileRef)"/>
          <xsl:with-param name ="editUrl" select ="concat($FORM_EDIT, '&amp;ID=',$thisNode/@ID)"/>
          <xsl:with-param name ="navUrl">
            <xsl:value-of select="$thisNode/@FileRef"/>
          </xsl:with-param>
          <xsl:with-param name ="imageHeight" select="$thisNode/@ImageHeight"/>
          <xsl:with-param name ="imageWidth" select="$thisNode/@ImageWidth"/>
          <xsl:with-param name="container">
            <xsl:choose>
              <xsl:when test="$thisNode/@FSObjType='1'">
                <xsl:value-of select="'true'"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="'false'"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
          <xsl:with-param name="rootFolder">
            <xsl:choose>
              <xsl:when test="$thisNode/@FSObjType='1'">
                <xsl:value-of select="$thisNode/@FileRef"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="''"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
          <xsl:with-param name="folderCTID">
            <xsl:choose>
              <xsl:when test="$thisNode/@FSObjType='1'">
                <xsl:value-of select="$thisNode/@ContentTypeId"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="''"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
          <xsl:with-param name ="itemTitle">
            <xsl:choose>
              <xsl:when test="$thisNode/@Title != ''">
                <xsl:value-of select="$thisNode/@Title"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:call-template name="getFileName">
                  <xsl:with-param name="FileNameAndExt" select="$thisNode/@FileLeafRef"/>
                </xsl:call-template>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:with-param>
          <xsl:with-param name ="coutId_Loc" select="concat($thisNode/@CheckedOutUserId, '_', $thisNode/@IsCheckedoutToLocal)"/>
          <xsl:with-param name ="absUrl" select="concat($HttpHost,$thisNode/@FileRef)"/>
        </xsl:call-template>
      </xsl:attribute>
    </input>
  </xsl:template>
  <xsl:template mode="Item" match="Row[../../@BaseViewID='40']" ddwrt:ghost="always">
    <xsl:param name="Fields" select="."/>
    <xsl:param name="Collapse" select="."/>
    <xsl:param name="Position" select="1"/>
    <xsl:param name="Last" select="1"/>
    <xsl:variable name="thisNode" select="."/>
    <xsl:variable name="fileExt">
      <xsl:call-template name="getFileExt">
        <xsl:with-param name="FileNameAndExt" select="$thisNode/@FileLeafRef"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="imageId" select="concat('tiledimage_',$thisNode/@ID)"/>
    <li>
      <xsl:attribute name="id">
        <xsl:value-of select="$imageId"/>
      </xsl:attribute>
      <xsl:attribute name="style">
        <xsl:if test="$Collapse">
          <xsl:value-of select="$CBXStyle"/>
        </xsl:if>
      </xsl:attribute>
      <!--Image Container -->
      <div>
        <xsl:attribute name="class">
          <xsl:value-of select="$StyleToApply"/>
        </xsl:attribute>
        <style type="text/css">
          #apdpopup {
          display:none !important;
          }
        </style>
        <!--Use call-template rather than apply-templates to ensure we at least show icons when thumbnails are removed-->
        <xsl:call-template name="RenderThumbnailPSMediaLibrary">
          <xsl:with-param name="thisNode" select="$thisNode"/>
          <xsl:with-param name="subDir" select="'_t'"/>
          <xsl:with-param name="resizeSquareSideLength" select="100"/>
        </xsl:call-template>
      </div>
      <script language="javascript">
        function getVideoId(uri) {
        var queryString = {};
        uri.replace(
        new RegExp("([^?=&amp;]+)(=([^&amp;]*))?", "g"),
        function($0, $1, $2, $3) { queryString[$1] = $3; }
        );
        return queryString['v'];
        };

        function Show(url,fileref) {
        link='/PSMediaLibrary/LocalVideo.aspx?video=' + fileref;
        if(url.toLowerCase().indexOf('youtube') != -1) {
          link = 'http://www.youtube.com/embed/' + getVideoId(url) + '?autoplay=1&amp;rel=0';
        }
        var options = {
          allowMaximize: false,
          showClose: true,
          autoSize: true,
          width: 853,
          height: 480,
          title: 'PS Media Library',
          url: link
        };

        SP.UI.ModalDialog.showModalDialog(options);
        }
      </script>

      <div style="top:-100px;">
        <a>
          <xsl:attribute name="href">
            <xsl:text>javascript:Show('</xsl:text>
            <xsl:value-of select="$thisNode/@URL"/>
            <xsl:text>','</xsl:text>
            <xsl:value-of select="$thisNode/@FileRef"/>
            <xsl:text>')</xsl:text>
          </xsl:attribute>
          <img src="/PSMediaLibrary/play.png" border="0" width="100" />
        </a>
      </div>
      <div>
        <xsl:attribute name="class">ms-assetpicker-tiled-mediumprops</xsl:attribute>
        <xsl:call-template name="ItemData"/>
        <xsl:choose>
          <xsl:when test="$Fields[@Name='Title']/following-sibling::FieldRef[@Name='URL']">
            <xsl:apply-templates select="$Fields[@Name='Title']" mode="PrintFieldWithECB">
              <xsl:with-param name="thisNode" select="$thisNode"/>
            </xsl:apply-templates>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="LinkFilenameNoMenuAP">
              <xsl:with-param name="thisNode" select="$thisNode"/>
              <xsl:with-param name="ShowNonContainerLinkOnly" select="1"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </div>
      <dl id="itemimages">
        <xsl:attribute name="class">
          <xsl:value-of select="$StyleForHiding"/>
        </xsl:attribute>
        <xsl:for-each select="$Fields[not(@Name='ThumbnailOnForm') and not(@Name='PreviewOnForm') and not(@Name='DocIcon') and not(@Name='Title')]">
          <dd>
            <xsl:attribute name="id">
              <xsl:value-of select="concat(@Name,'_',$thisNode/@ID)"/>
            </xsl:attribute>
            <xsl:attribute name="class">
              <xsl:value-of select="$StyleForHiding"/>
            </xsl:attribute>
            <span>
              <xsl:value-of select="@DisplayName"/>
            </span>
            <span>
              <xsl:apply-templates select="." mode="PrintFieldWithECB">
                <xsl:with-param name="thisNode" select="$thisNode"/>
              </xsl:apply-templates>
            </span>
          </dd>
        </xsl:for-each>
      </dl>
    </li>
  </xsl:template>
  <xsl:template name ="RenderThumbnailPSMediaLibrary" match ="FieldRef[@Name='ThumbnailOnForm'] " mode="Computed_body" ddwrt:dvt_mode="body">
    <xsl:param name="thisNode" select="."/>
    <xsl:param name="subDir" select="'_t'"/>
    <xsl:param name="classToApply" select="''"/>
    <xsl:param name="resizeSquareSideLength" select="0"/>
    <xsl:variable name="libUrl" select="substring-before($thisNode/@FileRef,$thisNode/@FileLeafRef)"/>
    <xsl:variable name="fileExt">
      <xsl:call-template name="getFileExt">
        <xsl:with-param name="FileNameAndExt" select="$thisNode/@FileLeafRef"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="fileName">
      <xsl:call-template name="getFileName">
        <xsl:with-param name="FileNameAndExt" select="$thisNode/@FileLeafRef"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="srcpath">
      <xsl:choose>
        <xsl:when test="$thisNode/@FSObjType='1'">
          <xsl:choose>
            <xsl:when test="string-length($thisNode/@AlternateThumbnailUrl) &gt; 0">
              <xsl:value-of select="$thisNode/@AlternateThumbnailUrl"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="GetFolderIconSourcePath">
                <xsl:with-param name="thisNode" select="$thisNode"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="string-length($thisNode/@AlternateThumbnailUrl) &gt; 0">
              <xsl:value-of select="$thisNode/@AlternateThumbnailUrl"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$thisNode/@ThumbnailExists.value='1'">
                  <xsl:value-of select="concat($libUrl,$subDir,'/',$fileName,'_',$fileExt,'.jpg')"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <xsl:when test="$fileExt = 'aspx'">
                      <xsl:value-of select="concat($RootSiteUrl,'/PSMediaLibrary/youtube.png')"/>
                    </xsl:when>
                    <xsl:when test="$fileExt = 'wma' or $fileExt = 'mp3'">
                      <xsl:value-of select="concat($RootSiteUrl,'/_layouts/images/AudioPreview.png')"/>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="concat($RootSiteUrl,'/_layouts/images/VideoPreview.png')"/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name ="ident" select="concat('thumbnail_',$thisNode/@ID)"/>
    <xsl:variable name="additionalStyleToApply">
      <xsl:choose>
        <xsl:when test="$resizeSquareSideLength = 0 or string-length($thisNode/@AlternateThumbnailUrl) &gt; 0"/>
        <xsl:when test="$thisNode/@ThumbnailExists.value='1'">
          <xsl:call-template name="getResizedAndCenteredStyle">
            <xsl:with-param name="imageWidth" select="$thisNode/@ImageWidth"/>
            <xsl:with-param name="imageHeight" select="$thisNode/@ImageHeight"/>
            <xsl:with-param name="defaultSize" select="$resizeSquareSideLength"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="$fileExt = 'aspx'">
          <xsl:call-template name="getResizedAndCenteredStyle">
            <xsl:with-param name="imageWidth" select="100"/>
            <xsl:with-param name="imageHeight" select="100"/>
            <xsl:with-param name="defaultSize" select="$resizeSquareSideLength"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="getResizedAndCenteredStyle">
            <xsl:with-param name="imageWidth" select="320"/>
            <xsl:with-param name="imageHeight" select="240"/>
            <xsl:with-param name="defaultSize" select="$resizeSquareSideLength"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="id">
      <xsl:value-of select="$ident"/>
    </xsl:variable>
    <xsl:variable name="class">
      <xsl:value-of select="$classToApply"/>
    </xsl:variable>
    <xsl:variable name="style">
      max-width:<xsl:value-of select="$XmlDefinition/List/@thumbnailsize"/>px;max-height:<xsl:value-of select="$XmlDefinition/List/@thumbnailsize"/>px;<xsl:value-of select="$additionalStyleToApply"/>
    </xsl:variable>
    <xsl:variable name="src">
      <xsl:choose>
        <xsl:when test="string-length($srcpath) &lt; 6">
          <xsl:value-of select="'/_layouts/images/Error.gif'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$srcpath"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <img id="{$id}" class="{$class}" style="{$style}" src="{$src}" title="{$thisNode/@_Comments}"/>
  </xsl:template>
  <xsl:template mode="Item" match="Row[../../@BaseViewID='4']" ddwrt:ghost="always">
    <xsl:param name="Fields" select="."/>
    <xsl:param name="Collapse" select="."/>
    <xsl:param name="Position" select="1" />
    <xsl:param name="Last" select="1" />
    <tr>
      <xsl:attribute name="class">
        <xsl:if test="$Position mod 2 = 0">ms-alternating</xsl:if>
      </xsl:attribute>
      <xsl:variable name="thisNode" select="."/>
      <xsl:for-each select="$Fields">
        <td>
          <xsl:if test="@ClassInfo='Menu' or @ListItemMenu='TRUE'">
            <xsl:attribute name="height">100%</xsl:attribute>
            <xsl:attribute name="onmouseover">OnChildItem(this)</xsl:attribute>
          </xsl:if>
          <xsl:attribute name="class">
            <xsl:call-template name="getTDClassValue">
              <xsl:with-param name="Type" select="@Type"/>
              <xsl:with-param name="ClassInfo" select="@ClassInfo"/>
            </xsl:call-template>
          </xsl:attribute>
          <xsl:apply-templates select="." mode="PrintFieldWithECB">
            <xsl:with-param name="thisNode" select="$thisNode"/>
            <xsl:with-param name="folderUrlAdditionalQueryString" select="$FolderUrlAdditionalQueryString"/>
          </xsl:apply-templates>
          <xsl:if test="position() = 1">
            <xsl:call-template name="ItemData">
              <xsl:with-param name ="thisNode" select="$thisNode"/>
            </xsl:call-template>
          </xsl:if>
        </td>
      </xsl:for-each>
    </tr>
  </xsl:template>
  <xsl:template name="clientData" ddwrt:ghost="always">
    <xsl:param name="id" select="''"/>
    <xsl:param name="canEdit" select="."/>
    <xsl:param name="previewExists" select="'Yes'"/>
    <xsl:param name="thumbnailExists" select="'Yes'"/>
    <xsl:param name="alternateThumbnailUrl" select="''"/>
    <xsl:param name="propsUrl" select="''"/>
    <xsl:param name="dwnlUrl" select="''"/>
    <xsl:param name="editUrl" select="''"/>
    <xsl:param name="navUrl" select="''"/>
    <xsl:param name="parentId" select="''"/>
    <xsl:param name="container" select="'false'"/>
    <xsl:param name="rootFolder" select="''"/>
    <xsl:param name="folderCTID" select="''"/>
    <xsl:param name="imageHeight" select ="."/>
    <xsl:param name="imageWidth" select="."/>
    <xsl:param name="itemTitle" select="''"/>
    <xsl:param name="coutId_Loc" select="''"/>
    <xsl:param name="absUrl" select="''"/>
    <xsl:variable name="data">
      id^<xsl:value-of select='$id'/>|propsUrl^<xsl:value-of select='$propsUrl'/>|dwnlUrl^<xsl:value-of select='$dwnlUrl'/>|editUrl^<xsl:value-of select='$editUrl'/>|navUrl^<xsl:value-of select='$navUrl'/>|parentId^<xsl:value-of select='$parentId'/>|isContainer^<xsl:value-of select='$container'/>|rootFolder^<xsl:value-of select='$rootFolder'/>|folderCTID^<xsl:value-of select='$folderCTID'/>|imageHeight^<xsl:value-of select='$imageHeight'/>|imageWidth^<xsl:value-of select='$imageWidth'/>|previewExists^<xsl:value-of select='$previewExists'/>|thumbnailExists^<xsl:value-of select='$thumbnailExists'/>|canEdit^<xsl:value-of select='$canEdit'/>|alternateThumbnailUrl^<xsl:value-of select='$alternateThumbnailUrl'/>|itemTitle^<xsl:value-of select='$itemTitle'/>|coutId_Loc^<xsl:value-of select='$coutId_Loc'/>|absUrl^<xsl:value-of select='$absUrl'/>
    </xsl:variable>
    <xsl:value-of select='string($data)'/>
  </xsl:template>
</xsl:stylesheet>
